package com.xq.spring.container;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.Marker;
import org.slf4j.MarkerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.xq.spring.beans.Chinese;
import com.xq.spring.beans.Person;

/**
 * ApplicationContext,常用的BeanFactory, 其功能包含: <li>默认预初始化所有的singleton Bean,可通过配置取消
 * <=>BeanFactory默认不会预初始化Bean
 * 
 * @author 郭凯强
 */
public class ApplicationContextBF {
	private static final Marker marker=MarkerFactory.getMarker(ApplicationContextBF.class.getName());
	private static final Logger logger=LoggerFactory.getLogger(ApplicationContextBF.class);
	public static void main(String[] args) {
		// 创建容器(事件源-主题)
		ApplicationContext context = new ClassPathXmlApplicationContext(
				"beans.xml");
		// 创建容器事件
		ContainerEvent containerEvent = new ContainerEvent(context, "TEST");
		// 发布容器事件
		context.publishEvent(containerEvent);
		// 让Bean获取Spring容器,并执行其中的方法
		Person person = context.getBean(Chinese.class);
		person.useAxe();
		// 获取FactoryBean的产品
		logger.debug(marker,"获取FactoryBean的产品={}",context.getBean("north"));
		// 获取FactoryBean本身
		logger.debug(marker,"获取FactoryBean本身={}",context.getBean("&north"));
	}
}
